package com.ibm.spatiotemp.server.datamodel.tenant;

import org.apache.log4j.Logger;

import com.ibm.spatiotemp.server.constants.Constant;
import com.ibm.spatiotemp.server.datamodel.tenant.datastore.TenantInfoStore;
import com.ibm.spatiotemp.server.datamodel.tenant.datastore.TenantStoreFactory;

public class TenantManager {
	public static Logger logger = Logger.getLogger(TenantManager.class);
	
	protected static TenantInfoStore tenantstore;
	
	static{
		init();
	}
	
	protected static void init(){
		/*create tenantstore instance via LocalConfig*/
		if(tenantstore == null)
		{
			tenantstore = TenantStoreFactory.getTenantInfoStoreInstance();
		}
	}
	
	public static void upsetTenant(Tenant tenant)
	{
		tenantstore.writeTenant(tenant);
	}
	
	public static int createTenant(String tenant_config_jsonstr){
		tenantstore.writeTenant(tenant_config_jsonstr);
		return Constant.TENANT_ACCESS_SUCCEED;
	}
	
	public static int deleteTenant(String tenantId){
		tenantstore.removeTenantById(tenantId);
		return Constant.TENANT_ACCESS_SUCCEED;
	}
	
	public static int updateTenant(String tenant_config_jsonstr)
	{
		tenantstore.writeTenant(tenant_config_jsonstr);
		return Constant.TENANT_ACCESS_SUCCEED;
	}
	
	public static Tenant getTenantbyID(String tenantid)
	{
		return tenantstore.getTenantById(tenantid);
	}
	
	
}
